package com.pingan.haofang.searchcloud.web.index.form;

import com.pingan.haofang.searchcloud.common.auth.AuthDataType;
import com.pingan.haofang.searchcloud.common.auth.ValidDataAuth;
import com.pingan.haofang.searchcloud.common.constants.Constants;
import com.pingan.haofang.searchcloud.common.validator.annotation.EnumOption;
import com.pingan.haofang.searchcloud.api.constants.EngineType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

/**
 * 索引基本信息表单
 *
 * @author baojie371
 * @date 17/5/5
 * @since 1.0.0
 */
@ApiModel(description = "索引基本信息form")
public class IndexForm {

    @Min(value = 1, message = "index.id.illegal")
    @ApiModelProperty(value = "索引ID，更新时提供", allowableValues = "range[1,infinity]", required = true)
    private Long id;

    @NotNull(message = "project.id.illegal")
    @Min(value = 1, message = "project.id.illegal")
    @ApiModelProperty(value = "项目ID", allowableValues = "range[1,infinity]", required = true)
    @ValidDataAuth(dataType = AuthDataType.PROJECT_ID)
    private Long projectId;

    @NotNull(message = "index.indexName.illegal")
    @Pattern(regexp = Constants.INDEX_NAME_PATTERN, message = "common.name.pattern.error")
    @Length(min = 1, max = 40, message = "index.indexName.illegal")
    @ApiModelProperty(value = "索引名称", required = true)
    private String indexName;

    @Length(max = 20, message = "index.indexAliasName.illegal")
    @ApiModelProperty(value = "索引别名", required = false)
    private String indexAliasName;

    @NotNull(message = "index.engineType.illegal")
    @EnumOption(enumClass = EngineType.class,
            message = "index.engineType.illegal")
    @ApiModelProperty(value = "引擎，0-SOLR，1-ES", allowableValues = "0,1", required = true)
    private Integer engineType;

    @ApiModelProperty(value = "集群名")
    private String clusterName = "default_solr";

    @Length(max = 50, message = "index.introduction.illegal")
    @ApiModelProperty(value = "索引简介", required = false)
    private String introduction;

    @Range(min = 1, max = 3, message = "metadata.shardCount.illegal")
    @ApiModelProperty(value = "分片数，range[1,3]，默认1", required = false)
    private Integer shardCount;

    @Range(min = 1, max = 3, message = "metadata.replicationFactor.illegal")
    @ApiModelProperty(value = "副本数，range[1,3]，默认1", required = false)
    private Integer replicationFactor;

    @Range(min = 1, max = 3, message = "metadata.maxShardsPerNode.illegal")
    @ApiModelProperty(value = "每个节点最大分片数，range[1,3]，默认1", required = false)
    private Integer maxShardsPerNode;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getProjectId() {
        return projectId;
    }

    public void setProjectId(Long projectId) {
        this.projectId = projectId;
    }

    public String getIndexName() {
        return indexName;
    }

    public void setIndexName(String indexName) {
        this.indexName = indexName;
    }

    public String getIndexAliasName() {
        return indexAliasName;
    }

    public void setIndexAliasName(String indexAliasName) {
        this.indexAliasName = indexAliasName;
    }

    public Integer getEngineType() {
        return engineType;
    }

    public void setEngineType(Integer engineType) {
        this.engineType = engineType;
    }

    public String getIntroduction() {
        return introduction;
    }

    public void setIntroduction(String introduction) {
        this.introduction = introduction;
    }

    public Integer getShardCount() {
        return shardCount;
    }

    public void setShardCount(Integer shardCount) {
        this.shardCount = shardCount;
    }

    public Integer getReplicationFactor() {
        return replicationFactor;
    }

    public void setReplicationFactor(Integer replicationFactor) {
        this.replicationFactor = replicationFactor;
    }

    public Integer getMaxShardsPerNode() {
        return maxShardsPerNode;
    }

    public void setMaxShardsPerNode(Integer maxShardsPerNode) {
        this.maxShardsPerNode = maxShardsPerNode;
    }

    public String getClusterName() {
        return clusterName;
    }

    public void setClusterName(String clusterName) {
        this.clusterName = clusterName;
    }

    @Override
    public String toString() {
        return "IndexForm{" +
                "id=" + id +
                ", projectId=" + projectId +
                ", indexName='" + indexName + '\'' +
                ", indexAliasName='" + indexAliasName + '\'' +
                ", engineType=" + engineType +
                ", clusterName='" + clusterName + '\'' +
                ", introduction='" + introduction + '\'' +
                ", shardCount=" + shardCount +
                ", replicationFactor=" + replicationFactor +
                ", maxShardsPerNode=" + maxShardsPerNode +
                '}';
    }
}
